// api/yapi.ts

import {
  UserPersonal,
  UserGetUserLogCount,
  UserModifyBase,
  UserSelfworkInfoPage,
  UserPage,
  UserDailyScore,
  UserWorkInfoList,
  UserRegister,
  UserLoginByAccount,
  UserOssSign,
  UserModifyPassword,
  UserCourseCatePage,
  UserCategoryAuth,
  UserCategoryPublicAuth,
  UserCoursePage,
  UserCodingProductList,
  UserPCcourseOrder,
  UserGetOrderDetail,
  UserPubworkInfoPage,
  UserGoodsPage,
  UserMyGoodsPage,
  UserBuyGoods,
  UserChangeGoodsFlag,
  UserScorePage,
  UserUpdateWorkInfo,
  UserActiveWorkRank,
  UserCommentWork,
  UserFavorComment,
  UserFavorWork,
  UserWorkInfoDetail,
  UserWorkInfoDetailStatic,
  UserAddChallenge,
  UserChallengePage,
  UserCommentPublicPage,
  UserWorkInfoDetailPublicStatic,
  UserWorkInfoPublicDetail,
  UserAddWorkInfo,
  UserCommentPage,
  UserCodingWeappScheme,
  UserCodingWeappQRcode,
  UserCodingActionLog,
  UserGetCourseVideoWithAccessKey,
  AIDraw,
  AISendDrawTask,
  AICheckPromptDetail,
  AIOssSign,
  AIWorkflowLogs,
  AIPubWorkInfo,
  AIMyWorkflowLogs,
  AIMyWorks,
  AIDeleteMyWorkInfo,
  AIModifyMyWorkInfo,
  AIPublicWorkInfoPage,
  AIComfyuiBalance,
  AIComfyuiServerQueue,
  AIComfyuiServerHistory,
  UserAiOrder,
  AICommentPage,
  AICommentWork,
  AIFavorWork,
  AICheckWorkInfoInteractive,
  AIAddWorkInfoDownload,
  AIFastGptApps,
  AIFetchDifyApps,
  AIDifyChatApps,
  AIDifyChatAppDetail,
  AIPublicIllustrationPosterPage,
  AIPublicIllustrationPosterDetail,
  AIToggleIllustrationPoster,
} from "../utils/coding/api";
import axios from "axios";


export const AI_BASE_URL = "http://localhost:6006";
// export const DIFY_BASE_URL = "http://localhost:7601";
export const DIFY_BASE_URL = "https://dify-adapter.codinghou.cn";
// export const DIFY_BASE_URL = "http://localhost:7601";
export const BASE_URL = "https://tutor.nongmokeji.com/api";

// export const BASE_URL = process.server
//   ? "https://tutor.nongmokeji.com/api"
//   : "https://tutor.nongmokeji.com/api";
export const AUTH_URL = "https://tutor.nongmokeji.com/api"
// export const BASE_URL = "http://localhost:20090/api";


export const deleteV1DeleteConversation = async (body: {
  conversation_id: string;
  appId: Number,
  appuserId: Number,
  platform: string,

}) => {
  const { token, getSession } = useAuth();
  let path = `/v1/conversations/${body.conversation_id}`;
  const method = "DELETE";
  return $fetch(`${DIFY_BASE_URL}${path}`, {
    method: `${method}`,
    headers: {
      Token: `${token.value ? token.value.replace("Bearer ", "") : ""}`,
    },
    body: body,
  });
}

export const getV1ConversationMessages = async (params: {
  conversation_id: string;
  first_id?: string;
  limit?: number;
}) => {
  const { token, getSession } = useAuth();
  let path = "/v1/messages";
  const method = "GET";
  return $fetch(`${DIFY_BASE_URL}${path}`, {
    method: `${method}`,
    headers: {
      Token: `${token.value ? token.value.replace("Bearer ", "") : ""}`,
    },
    query: params,
  });
}


export const getV1Conversations = async (params: any) => {
  const { token, getSession } = useAuth();
  let path = "/v1/conversations";
  const method = "GET";
  return $fetch(`${DIFY_BASE_URL}${path}`, {
    method: `${method}`,
    headers: {
      Token: `${token.value ? token.value.replace("Bearer ", "") : ""}`,
    },
    query: params,
  });
}
/**
 * @description 强制更新用户信息
 * @return 用户信息
 */
export const refreshUserPersonInfo = async (params: any) => {
  const { token, getSession } = useAuth();
  const { rawToken } = useAuthState();

  let newToken: any = await $fetch(`/api/auth/refresh`, {
    method: `GET`,
    headers: {
      authorization: `${token.value}`,
    },
    params,
  });
  rawToken.value = newToken;
  getSession();
  return newToken;
};

export const postUserOssSign = (params: any) => {
  let { path, method } = UserOssSign.requestConfig;
  const { token } = useAuth();
  return $fetch(`${BASE_URL}${path}`, {
    method: `${method}`,
    headers: {
      Token: `${token.value ? token.value.replace("Bearer ", "") : ""}`,
    },
    body: params,
  });
};

/**
 * @description 上传用户头像
 * @return 用户基本信息
 */
export const uploadData = (data: any) => {
  let path = "/coding/appuser/comm/uploadLocal";
  let method = "POST";
  // 创建 FormData 对象
  let formData = new FormData();
  // 通过 append() 方法来追加数据
  formData.append("file", data.file);
  const { token } = useAuth();
  return axios.post(`${BASE_URL}${path}`, formData, {
    method: `${method}`,
    headers: {
      "Content-Type": "multipart/form-data",
      Token: `${token.value ? token.value.replace("Bearer ", "") : ""}`,
    },
  });
};

/**
 * @description 修改用户基本信息
 * @return 用户基本信息
 */
export const postUserModifyBase = (params: any) => {
  let { path, method } = UserModifyBase.requestConfig;
  const { token } = useAuth();
  return $fetch(`${BASE_URL}${path}`, {
    method: `${method}`,
    headers: {
      Token: `${token.value ? token.value.replace("Bearer ", "") : ""}`,
    },
    body: params,
  });
};

/**
 * @description 获取用户信息修改记录
 * @return 用户信息修改记录
 */
export const postUserGetUserLogCount = (params: any) => {
  let { path, method } = UserGetUserLogCount.requestConfig;
  const { token } = useAuth();
  return $fetch(`${BASE_URL}${path}`, {
    method: `${method}`,
    headers: {
      Token: `${token.value ? token.value.replace("Bearer ", "") : ""}`,
    },
    body: params,
  });
};

/**
 * @description 获取用户邀请列表
 * @return 用户邀请列表
 */
export const postUserPage = (params: any) => {
  let { path, method } = UserPage.requestConfig;
  const { token } = useAuth();
  return $fetch(`${BASE_URL}${path}`, {
    method: `${method}`,
    headers: {
      Token: `${token.value ? token.value.replace("Bearer ", "") : ""}`,
    },
    body: params,
  });
};

/**
 * @description 普通用户注册
 * @return 注册结果
 */
export const postUserRegister = (params: any) => {
  let { path, method } = UserRegister.requestConfig;

  return $fetch(`${BASE_URL}${path}`, {
    method: `${method}`,

    body: params,
  });
};

/**
 * @description 普通用户登录
 * @return 用户登录结果
 */
export const postUserLoginByAccount = (params: any) => {
  let { path, method } = UserLoginByAccount.requestConfig;
  let url = `${AUTH_URL}${path}`
  return $fetch(url, {
    method: `${method}`,
    body: params,
  });
};
/**
 * @description 获取用户信息
 * @return 用户信息
 */
export const getUserPersonInfo = (params: any, tokenStr: any) => {
  let { path, method } = UserPersonal.requestConfig;
  return $fetch(`${AUTH_URL}${path}`, {
    method: `${method}`,
    headers: {
      Token: `${tokenStr}`,
    },
    params,
  });
};
/**
 * @description 修改密码
 * @return 修改密码
 */
export const postUserModifyPassword = (params: any) => {
  let { path, method } = UserModifyPassword.requestConfig;
  const { token } = useAuth();
  return $fetch(`${BASE_URL}${path}`, {
    method: `${method}`,
    headers: {
      Token: `${token.value ? token.value.replace("Bearer ", "") : ""}`,
    },
    body: params,
  });
};
/**
 * @description AI绘图-DiffSynth-Studio
 * @return AI绘图-DiffSynth-Studio
 */
export const postAiDrawDS = (params: any) => {
  let { path, method } = AIDraw.requestConfig;
  const { token } = useAuth();
  return $fetch(`${AI_BASE_URL}${path}`, {
    method: `${method}`,
    headers: {
      Token: `${token.value ? token.value.replace("Bearer ", "") : ""}`,
    },
    body: params,
  });
};
/**
 * @description AI绘图-sendDrawTask- comfyui
 * @return AI绘图-sendDrawTask- comfyui
 */
export const postSendDrawTask = (params: any) => {
  let { path, method } = AISendDrawTask.requestConfig;
  const { token } = useAuth();
  return $fetch(`${BASE_URL}${path}`, {
    method: `${method}`,
    headers: {
      Token: `${token.value ? token.value.replace("Bearer ", "") : ""}`,
    },
    body: params,
  });
};
/**
 * @description AI绘图-sendDrawTask- comfyui
 * @return AI绘图-sendDrawTask- comfyui
 */
export const postCheckPromptDetail = (params: any) => {
  let { path, method } = AICheckPromptDetail.requestConfig;
  const { token } = useAuth();
  return $fetch(`${BASE_URL}${path}`, {
    method: `${method}`,
    headers: {
      Token: `${token.value ? token.value.replace("Bearer ", "") : ""}`,
    },
    body: params,
  });
};
/**
 * @description AI绘图-ossSign- comfyui
 * @return AI绘图-ossSign- comfyui
 */
export const postOssSign = (params: any) => {
  let { path, method } = AIOssSign.requestConfig;
  const { token } = useAuth();
  return $fetch(`${BASE_URL}${path}`, {
    method: `${method}`,
    headers: {
      Token: `${token.value ? token.value.replace("Bearer ", "") : ""}`,
    },
    body: params,
  });
};
/**
 * @description AI绘图-postAIWorkflowLogs- comfyui
 * @return AI绘图-postAIWorkflowLogs- comfyui
 */
export const postAIWorkflowLogs = (params: any) => {
  let { path, method } = AIWorkflowLogs.requestConfig;
  const { token } = useAuth();
  return $fetch(`${BASE_URL}${path}`, {
    method: `${method}`,
    headers: {
      Token: `${token.value ? token.value.replace("Bearer ", "") : ""}`,
    },
    body: params,
  });
};
/**
 * @description AI绘图-postAIPubWorkInfo- comfyui
 * @return AI绘图-postAIPubWorkInfo- comfyui
 */
export const postAIPubWorkInfo = (params: any) => {
  let { path, method } = AIPubWorkInfo.requestConfig;
  const { token } = useAuth();
  return $fetch(`${BASE_URL}${path}`, {
    method: `${method}`,
    headers: {
      Token: `${token.value ? token.value.replace("Bearer ", "") : ""}`,
    },
    body: params,
  });
};
/**
 * @description AI绘图-AIMyWorkflowLogs- comfyui
 * @return AI绘图-AIMyWorkflowLogs- comfyui
 */
export const postAIMyWorkflowLogs = (params: any) => {
  let { path, method } = AIMyWorkflowLogs.requestConfig;
  const { token } = useAuth();
  return $fetch(`${BASE_URL}${path}`, {
    method: `${method}`,
    headers: {
      Token: `${token.value ? token.value.replace("Bearer ", "") : ""}`,
    },
    body: params,
  });
};
/**
 * @description AI绘图-AIMyWorks- comfyui
 * @return AI绘图-AIMyWorks- comfyui
 */
export const postAIMyWorks = (params: any) => {
  let { path, method } = AIMyWorks.requestConfig;
  const { token } = useAuth();
  return $fetch(`${BASE_URL}${path}`, {
    method: `${method}`,
    headers: {
      Token: `${token.value ? token.value.replace("Bearer ", "") : ""}`,
    },
    body: params,
  });
};
/**
 * @description AI绘图-AIDeleteMyWorkInfo- comfyui
 * @return AI绘图-AIDeleteMyWorkInfo- comfyui
 */
export const postAIDeleteMyWorkInfo = (params: any) => {
  let { path, method } = AIDeleteMyWorkInfo.requestConfig;
  const { token } = useAuth();
  return $fetch(`${BASE_URL}${path}`, {
    method: `${method}`,
    headers: {
      Token: `${token.value ? token.value.replace("Bearer ", "") : ""}`,
    },
    body: params,
  });
};
/**
 * @description AI绘图-AIModifyMyWorkInfo- comfyui
 * @return AI绘图-AIModifyMyWorkInfo- comfyui
 */
export const postAIModifyMyWorkInfo = (params: any) => {
  let { path, method } = AIModifyMyWorkInfo.requestConfig;
  const { token } = useAuth();
  return $fetch(`${BASE_URL}${path}`, {
    method: `${method}`,
    headers: {
      Token: `${token.value ? token.value.replace("Bearer ", "") : ""}`,
    },
    body: params,
  });
};
/**
 * @description AI绘图-AIPublicWorkInfoPage- comfyui
 * @return AI绘图-AIPublicWorkInfoPage- comfyui
 */
export const postAIPublicWorkInfoPage = (params: any) => {
  let { path, method } = AIPublicWorkInfoPage.requestConfig;
  const { token } = useAuth();
  return $fetch(`${BASE_URL}${path}`, {
    method: `${method}`,
    headers: {
      Token: `${token.value ? token.value.replace("Bearer ", "") : ""}`,
    },
    body: params,
  });
};
/**
 * @description AI绘图-AIComfyuiBalance- comfyui
 * @return AI绘图-AIComfyuiBalance- comfyui
 */
export const postAIComfyuiBalance = (params: any) => {
  let { path, method } = AIComfyuiBalance.requestConfig;
  const { token } = useAuth();
  return $fetch(`${BASE_URL}${path}`, {
    method: `${method}`,
    headers: {
      Token: `${token.value ? token.value.replace("Bearer ", "") : ""}`,
    },
    body: params,
  });
};
/**
 * @description AI绘图-AIComfyuiServerQueue- comfyui
 * @return AI绘图-AIComfyuiServerQueue- comfyui
 */
export const postAIComfyuiServerQueue = (params: any) => {
  let { path, method } = AIComfyuiServerQueue.requestConfig;
  const { token } = useAuth();
  return $fetch(`${BASE_URL}${path}`, {
    method: `${method}`,
    headers: {
      Token: `${token.value ? token.value.replace("Bearer ", "") : ""}`,
    },
    body: params,
  });
};
/**
 * @description AI绘图-AIComfyuiServerHistory- comfyui
 * @return AI绘图-AIComfyuiServerHistory- comfyui
 */
export const postAIComfyuiServerHistory = (params: any) => {
  let { path, method } = AIComfyuiServerHistory.requestConfig;
  const { token } = useAuth();
  return $fetch(`${BASE_URL}${path}`, {
    method: `${method}`,
    headers: {
      Token: `${token.value ? token.value.replace("Bearer ", "") : ""}`,
    },
    body: params,
  });
};
/**
 * @description AI绘图-UserAiOrder- comfyui
 * @return AI绘图-UserAiOrder- comfyui
 */
export const postUserAiOrder = (params: any) => {
  let { path, method } = UserAiOrder.requestConfig;
  const { token } = useAuth();
  return $fetch(`${BASE_URL}${path}`, {
    method: `${method}`,
    headers: {
      Token: `${token.value ? token.value.replace("Bearer ", "") : ""}`,
    },
    body: params,
  });
};

/**
 * @description 获取订单详情
 * @return 订单详情
 */
export const postUserGetOrderDetail = (params: any) => {
  let { path, method } = UserGetOrderDetail.requestConfig;
  const { token } = useAuth();
  return $fetch(`${BASE_URL}${path}`, {
    method: `${method}`,
    headers: {
      Token: `${token.value ? token.value.replace("Bearer ", "") : ""}`,
    },
    body: params,
  });
};

/**
 * @description 获取AICommentPage
 * @return AICommentPage
 */
export const postAICommentPage = (params: any) => {
  let { path, method } = AICommentPage.requestConfig;
  const { token } = useAuth();
  return $fetch(`${BASE_URL}${path}`, {
    method: `${method}`,
    headers: {
      Token: `${token.value ? token.value.replace("Bearer ", "") : ""}`,
    },
    body: params,
  });
};
/**
 * @description 获取AICommentWork
 * @return AICommentWork
 */
export const postAICommentWork = (params: any) => {
  let { path, method } = AICommentWork.requestConfig;
  const { token } = useAuth();
  return $fetch(`${BASE_URL}${path}`, {
    method: `${method}`,
    headers: {
      Token: `${token.value ? token.value.replace("Bearer ", "") : ""}`,
    },
    body: params,
  });
};
/**
 * @description 获取AIFavorWork
 * @return AIFavorWork
 */
export const postAIFavorWork = (params: any) => {
  let { path, method } = AIFavorWork.requestConfig;
  const { token } = useAuth();
  return $fetch(`${BASE_URL}${path}`, {
    method: `${method}`,
    headers: {
      Token: `${token.value ? token.value.replace("Bearer ", "") : ""}`,
    },
    body: params,
  });
};
/**
 * @description 获取AICheckWorkInfoInteractive
 * @return AICheckWorkInfoInteractive
 */
export const postAICheckWorkInfoInteractive = (params: any) => {
  let { path, method } = AICheckWorkInfoInteractive.requestConfig;
  const { token } = useAuth();
  return $fetch(`${BASE_URL}${path}`, {
    method: `${method}`,
    headers: {
      Token: `${token.value ? token.value.replace("Bearer ", "") : ""}`,
    },
    body: params,
  });
};
/**
 * @description 获取AIAddWorkInfoDownload
 * @return AIAddWorkInfoDownload
 */
export const postAIAddWorkInfoDownload = (params: any) => {
  let { path, method } = AIAddWorkInfoDownload.requestConfig;
  const { token } = useAuth();
  return $fetch(`${BASE_URL}${path}`, {
    method: `${method}`,
    headers: {
      Token: `${token.value ? token.value.replace("Bearer ", "") : ""}`,
    },
    body: params,
  });
};
/**
 * @description 获取fastGPT应用结果获取
 * @return fastGPT应用结果获取
 */
export const postAIFastGptApps = (params: any) => {
  let { path, method } = AIFastGptApps.requestConfig;
  const { token } = useAuth();
  return $fetch(`${BASE_URL}${path}`, {
    method: `${method}`,
    headers: {
      Token: `${token.value ? token.value.replace("Bearer ", "") : ""}`,
    },
    body: params,
  });
};
/**
 * @description 获取dify应用结果获取
 * @return dify应用结果获取
 */
export const postAIFetchDifyApps = (params: any) => {
  let { path, method } = AIFetchDifyApps.requestConfig;
  const { token } = useAuth();
  return $fetch(`${BASE_URL}${path}`, {
    method: `${method}`,
    headers: {
      Token: `${token.value ? token.value.replace("Bearer ", "") : ""}`,
    },
    body: params,
  });
};
/**
 * @description 获取dify聊天应用
 * @return dify聊天应用
 */
export const postAIDifyChatApps = (params: any) => {
  let { path, method } = AIDifyChatApps.requestConfig;
  const { token } = useAuth();
  let url = `${BASE_URL}${path}`
  return $fetch(url, {
    method: `${method}`,
    headers: {
      Token: `${token.value ? token.value.replace("Bearer ", "") : ""}`,
    },
    body: params,
  });
};
/**
 * @description 获取dify聊天应用详情
 * @return dify聊天应用
 */
export const postDifyChatAppDetail = (params: any) => {
  let { path, method } = AIDifyChatAppDetail.requestConfig;
  const { token } = useAuth();
  let url = `${BASE_URL}${path}`
  // console.log("%c Line:662 🥑 url", "color:#2eafb0", url,method,params);
  return $fetch(url, {
    method: `${method}`,
    headers: {
      Token: `${token.value ? token.value.replace("Bearer ", "") : ""}`,
    },
    body: params,
  });
};
/**
 * @description 获取配图古诗词
 * @return 配图古诗词
 */
export const postAIPublicIllustrationPosterPage = (params: any) => {
  let { path, method } = AIPublicIllustrationPosterPage.requestConfig;
  const { token } = useAuth();
  let url = `${BASE_URL}${path}`
  // console.log("%c Line:662 🥑 url", "color:#2eafb0", url,method,params);
  return $fetch(url, {
    method: `${method}`,
    headers: {
      Token: `${token.value ? token.value.replace("Bearer ", "") : ""}`,
    },
    body: params,
  });
};
/**
 * @description 获取配图古诗词详情
 * @return 配图古诗词详情
 */
export const postAIPublicIllustrationPosterDetail = (params: any) => {
  let { path, method } = AIPublicIllustrationPosterDetail.requestConfig;
  const { token } = useAuth();
  let url = `${BASE_URL}${path}`
  // console.log("%c Line:662 🥑 url", "color:#2eafb0", url,method,params);
  return $fetch(url, {
    method: `${method}`,
    headers: {
      Token: `${token.value ? token.value.replace("Bearer ", "") : ""}`,
    },
    body: params,
  });
};
/**
 * @description 切换配图古诗词
 * @return 切换配图古诗词
 */
export const postAIToggleIllustrationPoster = (params: any) => {
  let { path, method } = AIToggleIllustrationPoster.requestConfig;
  const { token } = useAuth();
  let url = `${BASE_URL}${path}`
  return $fetch(url, {
    method: `${method}`,
    headers: {
      Token: `${token.value ? token.value.replace("Bearer ", "") : ""}`,
    },
    body: params,
  });
};
